package com.lemon.smartsafety.ui.adapter.safe.nfcorqrcode;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.result.safe.ResultCheckNfc;
import com.lemon.smartsafety.ui.adapter.safe.data.BuildingListAdapter;
import com.lemon.smartsafety.ui.adapter.safe.inspection.CheckItemFlowAdapter;
import com.lemon.smartsafety.utils.common.StringUtils;

import java.util.List;

import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * 项目名称：SmartSafeCode
 * 类描述：
 * 创建人：Fargo
 * 创建时间：2016/12/22 9:51
 * 修改人：Fargo
 * 修改时间：2016/12/22 9:51
 * 修改备注：
 */
public class CodeCheckItemFlowAdapter extends LemonRcvAdapter<ResultCheckNfc.FlowListEntity> {
    private RecyclerTClickListener<ResultCheckNfc.FlowListEntity> mListener;

    public CodeCheckItemFlowAdapter(@Nullable List<ResultCheckNfc.FlowListEntity> data, RecyclerTClickListener listener) {
        super(data);
        this.mListener = listener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new CodeCheckItemFlowAdapter.CheckItemFlowItem();
    }

    public class CheckItemFlowItem implements AdapterItem<ResultCheckNfc.FlowListEntity> {


        LinearLayout ripple;
        TextView tvNumber;
        TextView        tvFlowTitle;
        TextView        tvRemark;
        ImageView ivStatusLight;


        private ResultCheckNfc.FlowListEntity mData;
        private int                       mPosition;

        @Override
        public int getLayoutResId() {
            return R.layout.item_inspection_check_item_flow;
        }

        @Override
        public void bindViews(View root) {
            ripple = (LinearLayout) root.findViewById(R.id.ripple);
            tvNumber = (TextView) root.findViewById(R.id.tv_number);
            tvFlowTitle = (TextView) root.findViewById(R.id.tv_flow_title);
            tvRemark = (TextView) root.findViewById(R.id.tv_remark);
            ivStatusLight = (ImageView) root.findViewById(R.id.iv_status_light);
        }

        @Override
        public void setViews() {
            ripple.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (mListener != null) {
                        mListener.onItemClick(mData, mPosition);
                    }
                }
            });
           /* ripple.setOnRippleCompleteListener(new RippleView.OnRippleCompleteListener() {
                @Override
                public void onComplete(RippleView rippleView) {
                    if (mListener != null) {
                        mListener.onItemClick(mData, mPosition);
                    }
                }
            });*/
        }

        @Override
        public void handleData(ResultCheckNfc.FlowListEntity data, int position) {
            mData = data;
            mPosition = position;
            String number = (position + 1) + "、";
            tvNumber.setText(number + "");
            tvFlowTitle.setText(StringUtils.nullValue(data.getFlowName()));

            String statusString = StringUtils.nullValue(data.getStatus(), "0");
            if ("0".equals(statusString)) {
                ivStatusLight.setVisibility(View.GONE);
            } else {
                ivStatusLight.setVisibility(View.VISIBLE);
            }
            BuildingListAdapter.setStatusLight(statusString, ivStatusLight);

            String sRemark = StringUtils.nullValue(data.getCheckWay(), "暂无");
            tvRemark.setText(sRemark.trim());

            if (StringUtils.getBoolean(data.getIsIgnore())) {
                tvNumber.setTextColor(tvNumber.getContext().getResources().getColor(R.color.colorDisable));
                tvFlowTitle.setTextColor(tvNumber.getContext().getResources().getColor(R.color.colorDisable));
                tvRemark.setTextColor(tvNumber.getContext().getResources().getColor(R.color.colorDisable));
            } else {
                tvNumber.setTextColor(tvNumber.getContext().getResources().getColor(R.color.colorTextPrimary));
                tvFlowTitle.setTextColor(tvNumber.getContext().getResources().getColor(R.color.colorTextPrimary));
                tvRemark.setTextColor(tvNumber.getContext().getResources().getColor(R.color.colorTextPrimary));
            }
        }
    }
}